<template>
  <div class="page-main">
    <page-tools>
      <el-button @click="handleOpenDialog('new')" type="primary">新建问诊</el-button>
    </page-tools>
    <base-table ref="tableRef" :table-config="tableConfig" :table-columns="tableColumns">
      <template #tools="{ scope }">
        <el-button size="small" type="text" style="color: red" @click="handleDelete(scope.row.id)">删除</el-button>
      </template>
    </base-table>
    <Loger ref="pageLoger" :size="'small'" @submit="handleSubmit" @cancel="handelCancel" />
  </div>
</template>

<script lang="ts" setup>
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   * @Name: inquiry
   * @Author: Zhang Ziyi
   * @Email: 15227974559@163.com
   * @Date: 2022-06-11 23:46
   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

  import { TableConfigType } from '@/components/common-table/common-table-type';
  import { reactive, ref, nextTick } from 'vue';
  import Message from '@/utils/message';
  import { ElMessageBox } from 'element-plus';
  import { Http } from '@/utils/http';
  const module = '';
  console.log(module);
  // 声明ref
  const pageLoger = ref();
  const tableRef = ref();
  // 声明数据
  // 表格
  const tableConfig = reactive<TableConfigType>({
    url: `/xxx/list`,
    border: true,
    index: true,
    check: false,
    tools: true,
    toolsWidth: 200,
  });
  const tableColumns = ref([]);
  // loger
  const logerType = ref<'new' | 'edit' | 'show'>('new');
  // 打开弹框
  const handleOpenDialog = (type: 'new' | 'edit' | 'show', row?: any) => {
    console.log(row);
    logerType.value = type;
    const title = (type === 'new' ? '新建' : type === 'edit' ? '编辑' : '查看') + '问诊';
    pageLoger.value.open(title);
    nextTick(() => {});
  };
  // 弹框确定
  const handleSubmit = (cb: () => void) => {
    cb();
  };
  // 弹框取消
  const handelCancel = (cb: () => void) => {
    cb();
  };
  // 表格删除
  const handleDelete = (id: { id: number }) => {
    ElMessageBox.confirm('您确定要删除该企业吗？', '提示', { type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消' })
      .then(() => {
        Http.post(`/xxx/delete`, { id }).then(() => {
          Message.success('删除成功！');
          tableRef.value.initTableData();
        });
      })
      .catch(() => {
        Message.info('您点击了取消');
      });
  };
</script>

<style lang="scss" scoped></style>
